import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.swing.*;

public class CardDrawPanel extends JPanel
{
	private final int WIDTH = 340;
	private final int HEIGHT = 220;

	private JLabel headingLabel;
	private ChanceChestPanel ccPanel; 
	private JButton button;
	
	private int returnValue; // 0 - no, 1 - yes
	
	public CardDrawPanel(String name, String type)
	{
		setPreferredSize(new Dimension(WIDTH, HEIGHT));
		setBackground(new Color(200,222,186));
		returnValue = -1; // used to force to click button
		
		ccPanel = new ChanceChestPanel();
		
		if(type == "chance")
		{	
			button = new JButton("Chance");
			headingLabel = new JLabel("Draw a Chance card:");
			add(headingLabel);
			ccPanel.changeImageChance(name + ".jpg");
		}
		else if(type == "communitychest")
		{
			button = new JButton("Community Chest");
			headingLabel = new JLabel("Draw a Community Chest card:");
			add(headingLabel);
			ccPanel.changeImageChest(name + ".jpg");
		}		
		
		add(button);
		button.addActionListener(new ButtonListener());
		add(ccPanel);
		ccPanel.setVisible(false);		
	}

	private class ButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			//Object source = event.getSource();
			returnValue = 1;
			button.setEnabled(false);
			ccPanel.setVisible(true);
		}
	}
		
	public int getReturnValue()
	{
		return returnValue;
	}

	public void resetReturnValue()
	{
		returnValue = -1;
	}
}